package com.wd.health.view.activity.mine;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.gyf.immersionbar.ImmersionBar;
import com.wd.health.R;
import com.facebook.drawee.view.SimpleDraweeView;
import com.wd.health.view.activity.home.HomeActivity;

public class SetActivity extends AppCompatActivity implements View.OnClickListener {

    private TextView tv_tuichudenglu;
    private SimpleDraweeView sdv_user;
    private TextView tv_user_name;
    private SharedPreferences user;
    private ImageView img_back;
    private LinearLayout user_set;
    private LinearLayout tl_updatepwd;
    private LinearLayout ll_yaoqing;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ImmersionBar.with(this).init();
        setContentView(R.layout.activity_set);
        initView();
        initData();
    }

    private void initData() {

    }

    private void initView() {
        tv_tuichudenglu = findViewById(R.id.tv_tuichudenglu);
        sdv_user = findViewById(R.id.sdv_user);
        tv_user_name = findViewById(R.id.tv_user_name);
        img_back = findViewById(R.id.img_back);
        user_set = findViewById(R.id.user_set);
        tl_updatepwd = findViewById(R.id.tl_updatepwd);
        ll_yaoqing = findViewById(R.id.ll_yaoqing);
        user = getSharedPreferences("user", Context.MODE_PRIVATE);
        String nickName = user.getString("nickName", "");
        String headPic = user.getString("headPic", "");
        tv_user_name.setText(nickName);
        sdv_user.setImageURI(headPic);
        img_back.setOnClickListener(this);
        tv_tuichudenglu.setOnClickListener(this);
        user_set.setOnClickListener(this);
        tl_updatepwd.setOnClickListener(this);
        ll_yaoqing.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            //回退
            case R.id.img_back:
                finish();
                break;
            //退出登录
            case R.id.tv_tuichudenglu:
                SharedPreferences.Editor edit = user.edit();
                edit.clear();
                edit.commit();
                Toast.makeText(SetActivity.this, "退出登录成功", Toast.LENGTH_SHORT).show();
                Intent intent = new Intent(SetActivity.this, HomeActivity.class);
                startActivity(intent);
                finish();
                break;
            //用户信息
            case R.id.user_set:
                Intent intent1 = new Intent(SetActivity.this, UserSetActivity.class);
                startActivity(intent1);
                break;
            //修改密码
            case R.id.tl_updatepwd:
                Intent intent2 = new Intent(SetActivity.this, UpdatePwdActivity.class);
                startActivity(intent2);
                break;
            //邀请好友
            case R.id.ll_yaoqing:
                Intent intent3 = new Intent(SetActivity.this, InviteFriendActivity.class);
                startActivity(intent3);
                break;
        }
    }
}